package com.marketingexpert.controller.streammgnt;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.marketingexpert.exception.MarketingExpertException;
import com.marketingexpert.service.snsmgnt.SnsServiceFactory;
import com.marketingexpert.service.streammgnt.StreamService;
import com.marketingexpert.util.Resources;

public class DeletePanelController implements Controller {

	private static Logger logger = Logger.getLogger(DeletePanelController.class);
	
	private StreamService streamService = null;
	
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		response.setContentType("application/text;charset=GBK"); 
		response.setHeader("Pragma", "No-cache"); 
		response.setHeader("Cache-Control", "no-cache"); 
		response.setHeader("Cache-Control", "no-store"); 
		response.setDateHeader("Expires", 0);  
		PrintWriter out = response.getWriter(); 	
		
		String panelId = request.getParameter("panelId");
		
		if(panelId == null || panelId.trim().equals("")) {
			logger.error(Resources.getString("DeletePanelController.lackParam"));
			out.print(Resources.getString("DeletePanelController.deleterOccurError"));
			return null;
		}
		
		try {
			streamService.deletePanle(Integer.parseInt(panelId));
		} catch(MarketingExpertException e) {
			logger.error(Resources.getString("DeletePanelController.deleterOccurError"), e);
			throw e;
		}
		
		
		out.print(Resources.getString("DeletePanelController.deleterSuccess"));
		return null;
	}

	public StreamService getStreamService() {
		return streamService;
	}

	public void setStreamService(StreamService streamService) {
		this.streamService = streamService;
	}

}
